package com.itheima.goods.controller;

import com.itheima.goods.pojo.Category;
import com.itheima.goods.service.CategoryService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll() {
        return categoryService.categoryCare();
    }

    /**
     * 添加分类信息
     * @param category
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Category category){
        return this.categoryService.addCategory(category);
    }

    /**
     * 分页查询分类信息
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search/{page}/{size}")
    //加路径变量
    public Result findByPage(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
       return this.categoryService.findByPage(page,size);
    }

    /**
     * 根据id查询分类信息
     * @param id
     * @return
     */
    @GetMapping("/search/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return this.categoryService.findById(id);
    }

    /**
     * 根据id修改分类信息
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    public Result updateCategoryById(@PathVariable("id") Integer id, @RequestBody Category categories){
        return this.categoryService.updateCategoryById(id,categories);

    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id")Integer id){
        return categoryService.delete(id);
    }
//    @PostMapping("search/{page}/{size}")
//    public Result search(@PathVariable("page")Integer page,
//                         @PathVariable("size")Integer size,
//                         @RequestBody Object searchMap){
//        return categoryService.searchByPageQuery(page,size,searchMap);
//    }
}
